package Controller;

import Pojo.Feedback;
import Service.impl.FeedbackServiceImpl;
import com.alibaba.fastjson.JSON;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

public class FeedBackQueryByRoomIdServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        response.setCharacterEncoding("UTF-8");
        try {
            String roomIdGet = request.getParameter("roomIdGet");
            String orderBy = request.getParameter("orderBy");
            if(orderBy == null || orderBy.equals("") ){
                orderBy="desc";
            }
            if(roomIdGet != null && !roomIdGet.equals("")){
                FeedbackServiceImpl feedbackService=new FeedbackServiceImpl();
                List<Feedback> feedbackList=feedbackService.FeedBackQueryByRoomId(Integer.parseInt(roomIdGet),orderBy);
                response.getWriter().print(JSON.toJSONString(feedbackList));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
